// pages/animation/animation.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    classArr: [],
    aniObj: null,
    animation: null,
    timer: null,
    rotateIndex:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    // 创建动画对象
    let ani = wx.createAnimation({
      duration: 2000
    })
    // 设置动画类型
    // ani = ani.scale(2, 2).step().rotate(45).step();
    // console.log(ani)
    // this.setData({
    //   aniObj: ani.export()
    // })

    this.setData({
      animation: ani
    })
    this.startAnimation();
  },
  startAnimation() {
    // 设置动画类型
    if (this.data.animation.option.transition.duration == 2000) {
      const animationData = this.data.animation.scale(2, 2).step();
      this.setData({
        aniObj: animationData.export()
      }, () => {
        this.data.animation.option.transition.duration = 1000;
        const timer = setTimeout(() => {
          this.startAnimation();
        }, 2000);
        this.setData({
          timer,
        });
      });
    } else {
      const animationData = this.data.animation.rotate(90 * (this.data.rotateIndex += 1)).step();
      this.setData({
        aniObj: animationData.export()
      }, () => {
        const timer = setTimeout(() => {
          this.startAnimation();
        }, 1000);
        this.setData({
          timer,
        });
      });
    }
  },
  moveToRight() {
    let classArr = this.data.classArr.length ? [] : ['to-right'];
    this.setData({
      classArr
    })
  }
})